home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / shared / freeman / funclink.m < prev    next >
Text File  |  1993-10-27  |  2KB  |  62 lines

  1. BeginPackage["FunctionalLink`"]
  2.  
  3. fln::usage = "fln[inNumber,outNumber,ioPairs,eta,alpha,numIters]"
  4. flnTest::usage = "flnTest[outputWts,ioPairVectors]"
  5.  
  6. Begin["`Private`"]    (* begin the private context *)
  7.  
  8.  
  9. fln[inNumber_,outNumber_,ioPairs_,eta_,alpha_,numIters_] :=
  10.   Module[{outWts,ioP,inputs,outputs,outDesired, 
  11.             outVals,outLastDelta,outDelta,outErrors},
  12.   outVals={};
  13.   outWts = Table[Table[Random[Real,{-0.1,0.1}],{inNumber}],{outNumber}];
  14.   outLastDelta = Table[Table[0,{inNumber}],{outNumber}];
  15.   errorList = Table[
  16.                     (* begin forward pass *)
  17.       ioP=ioPairs[[Random[Integer,{1,Length[ioPairs]}]]];
  18.      inputs=ioP[[1]];
  19.      outDesired=ioP[[2]];
  20.      outputs = outWts.inputs; (* output-layer outputs *)
  21.                     (* calculate errors *)
  22.      outErrors = outDesired-outputs;
  23.      outDelta= outErrors;
  24.                         (* update weights *)
  25.      outLastDelta= eta Outer[Times,outDelta,inputs]+alpha outLastDelta;
  26.      outWts += outLastDelta;
  27.         outErrors.outErrors, (* this puts the error on the list *)
  28.         {numIters}]    ;     (* this many times, Table ends here *)
  29.  Print["New output-layer weight matrix: "];
  30.  Print[]; Print[outWts];Print[];  
  31.  outVals=flnTest[outWts,ioPairs];  
  32.  errorPlot = ListPlot[errorList, PlotJoined->True];
  33.  Return[{outWts,errorList,errorPlot,outVals}];
  34.  ]                        (* end of Module *)
  35.  
  36.  
  37. flnTest[outputWts_,ioPairVectors_] :=
  38.   Module[{inputs,hidden,outputs,desired,errors,i,len,
  39.               errorTotal,errorSum},
  40.    inputs=Map[First,ioPairVectors];
  41.    desired=Map[Last,ioPairVectors];
  42.    len = Length[inputs];
  43.    outputs=inputs.Transpose[outputWts];
  44.    errors= desired-outputs;
  45.    For[i=1,i<=len,i++,
  46.             (*Print["Input ",i," = ",inputs[[i]]];*)
  47.           Print[" Output ",i," = ",outputs[[i]]," desired = ",
  48.               desired[[i]]," Error = ",errors[[i]]];Print[];
  49.           ];            (* end of For *)
  50.       (*Print["errors= ",errors];Print[];*)
  51.    errorSum = Apply[Plus,errors^2,2]; (* second level *)
  52.    (*Print["errorSum= ",errorSum];Print[];*)
  53.    errorTotal = Apply[Plus,errorSum];
  54.    (*Print["errorTotal= ",errorTotal];*)
  55.    Print["Mean Squared Error = ",errorTotal/len];
  56.    Return[outputs];
  57.    ]                    (* end of Module *)
  58.  
  59.  
  60. End[]         (* end the private context *)
  61.  
  62. EndPackage[]  (* end the package context *)